<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="renderer" content="webkit">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta name="author" content="tyler chao">
  <meta name="keywords" content="keywords">
  <meta name="description" content="description">
  <title><{$title}></title>
  <link rel="stylesheet" href="<{$env.app.res_url}>/css/mobile.min.css">
  <link rel="stylesheet" href="<{$env.app.res_url}>/css/main.min.css">
</head>
<body>
<header class="fixed">
  <div class="top-bar" data-topbar>
    <div class="pos-left">
      <a href="javascript:history.back();" class="icon-arrow-back"></a>
    </div>
    <h1><{$title}></h1>
    <div class="pos-right"><a href="" class="icon-refresh"></a></div>
  </div>
</header>
<main id="main" class="container no-margin">

  <div class="top-bar reverse">
    <form action="<{$link_url}>" class="row blank" id="delivery_frm" name="delivery_frm" method="post">
      <div class="grid-3 columns" style="width:30%;">
        <select name="sel_type" id="sel_type">
          <option value="order_bn">订单号</option>
          <option value="delivery_bn">发货单号</option>
          <option value="ship_mobile">手机</option>
        </select>
      </div>
      <div class="grid-1 columns">
        <input type="search" name="sel_keywords" id="sel_keywords" placeholder="请输入关键词搜索">
      </div>
    </form>
  </div>

  <div class="tabs-content">
    <{if $dataList}>
    <div class="content active" id="content11">
        <div class="container blank order-item">
            <{include file="order/order_list_more.html"}>
        </div>
        
        <{if $pageSize > 1}>
        <div class="text-center"><a href="<{$link_url}>" class="act-loadmore" rel="1"><i class="icon-refresh"></i> 点击查看更多</a></div>
        <{/if}>
    </div>
    <{else}>
        <div class="no_content" style="text-align:center;">暂时没有业务需要处理哦，亲...</div>
    <{/if}>
  </div>
</main>


<div id="reject_modal" class="modal center" data-modal>
  <a href="" class="close-modal">&times;</a>
  <header>拒单</header>
  <article>
    <form action="" method="post" class="form-vertical collapse" id="reject_form">
      <input type="hidden" name="delivery_id" id="refuse_delivery_id" value="">
      <input type="hidden" name="status" id="refuse_status" value="2">
      <div class="form-row">
        <div class="grid-12">
          <label for="for_reason">
            *选择拒单理由：
            <select name="refuse_reason_id" id="refuse_reason_id">
                <option value="">=请选择=</option>
                <{if $refuse_reasons}>
                <{foreach from=$refuse_reasons item=reason}>
                <option value="<{$reason.reason_id}>"><{$reason.reason_name}></option>
                <{/foreach}>
                <{/if}>
            </select>
          </label>
        </div>
      </div>
      <div class="form-row">
        <div class="grid-6 columns">
          <button type="button" id="refuse_button" class="primary expand" onClick="ajax_refuse_confirm()">确认拒单</button>
        </div>
        <div class="grid-6 columns">
          <a href="" class="btn close-modal expand">关闭</a>
        </div>
      </div>
    </form>
  </article>
</div>


<{include file="store/footer.html"}>
<script>
$('.act-loadmore').on('click', function(e) {
    e.preventDefault();
    var $target = $(e.target);
    var pageSize  = parseInt("<{$pageSize}>");
    var page      = parseInt($target.attr('rel')) + 1;
    
    $.post($target.attr('href'), {'flag': 'ajax', 'page': $target.attr('rel')}, function(rs) {
      if (rs) {
          $target.parent().prev('div').append(rs);
          $target.html($target.data('text')).attr('rel', +$target.attr('rel') + 1);
          
          if(pageSize <= page)
          {
              $target.parent().html('<span class="text-reverse">没有更多数据了...</span>');
          }
      }
      else {
        $target.parent().html('<span class="text-reverse">没有更多数据了</span>');
      }
    });
});

function ajax_confirm(delivery_id)
{
    var confirm_text    = "确认接单吗？\n   请确认商品库存、配送等方面是否满足条件";
    var ajax_url        = "<{$delivery_link.doConfirm}>";
    
    if(delivery_id == "")
    {
        alert("无效操作!");
        return false;
    }
    
    if(confirm(confirm_text)) {
        $.post(ajax_url, {'delivery_id': delivery_id}, function(rs) {
            if (rs) {
                json = JSON.parse(rs);
                if(json.res == 'succ')
                {
                    $("#delivery_operate_" + delivery_id).html('<a href="javascript:;" class="btn small primary" onclick="ajax_consign('+ delivery_id +')">立即发货</a>');
                    $(document).mobile('tips', 'show', [json.msg, 'msg']);
                }
                else
                {
                    $(document).mobile('tips', 'show', [json.msg, 'msg']);
                }
            }else {
                $(document).mobile('tips', 'show', ['操作失败', 'msg']);
            }
        });
    }
}

function show_map(delivery_id)
{
    var $this = $("#show_map_id_"+ delivery_id);
    var store_addr = $this.attr("alt");
    var position_url = '<{$delivery_link.mapLink}>';
    
    window.open(position_url+"?store_addr="+store_addr);
}

function refuse_confirm(delivery_id)
{
    $('#reject_form').find('input[name=delivery_id]').val(delivery_id);
}

$('.close-modal').on('click', function(e) {
    e.preventDefault();
    
    $('#reject_form').find('input[name=delivery_id]').val('');
});

function ajax_refuse_confirm()
{
    var delivery_id     = $("#refuse_delivery_id").val();
    var confirm_text    = '请确认是否直接拒绝该笔订单？';
    var ajax_url        = "<{$delivery_link.doRefuse}>";
    
    var refuse_reason   = $("#refuse_reason_id").val();
    if(delivery_id == "")
    {
        alert("无效操作!");
        return false;
    }
    if(refuse_reason == "")
    {
        alert("请选择一个拒单理由!");
        return false;
    }
    
    if(confirm(confirm_text)) {
        
        $('#reject_modal').mobile('modal', 'close');
        
        $.post(ajax_url, {'delivery_id': delivery_id, 'refuse_reason_id': refuse_reason}, function(rs) {
            if (rs) {
                json = JSON.parse(rs);
                if(json.res == 'succ')
                {
                    $("#delivery_operate_" + delivery_id).html('<span style="color: red; font-weight: bold">订单已拒绝!&nbsp;</span>');
                    $(document).mobile('tips', 'show', [json.msg, 'msg']);
                }
                else
                {
                    $(document).mobile('tips', 'show', [json.msg, 'msg']);
                }
            }else {
                $(document).mobile('tips', 'show', ['操作失败', 'msg']);
            }
        });
    }
}

function showTitle(item_id)
{
    var $this = $("#item_title_"+ item_id);
    $this.css('-webkit-line-clamp', $this.css('-webkit-line-clamp') == 1 ? 'inherit' : '');
}

function ajax_consign(delivery_id)
{
    var confirm_text    = "确认发货吗？\n   请确认商品是否已备货并妥善包装等待出库";
    var ajax_url        = "<{$delivery_link.doConsign}>";
    
    if(delivery_id == "")
    {
        alert("无效操作!");
        return false;
    }
    
    if(confirm(confirm_text)) {
        $.post(ajax_url, {'delivery_id': delivery_id}, function(rs) {
            if (rs) {
                json = JSON.parse(rs);
                if(json.res == 'succ')
                {
                    $("#delivery_operate_" + delivery_id).html('<a href="<{$delivery_link.signPage}>?delivery_id='+ delivery_id +'" class="btn small primary">立即核销</a>');
                    $(document).mobile('tips', 'show', [json.msg, 'msg']);
                }
                else
                {
                    $(document).mobile('tips', 'show', [json.msg, 'msg']);
                }
            }else {
                $(document).mobile('tips', 'show', ['操作失败', 'msg']);
            }
        });
    }
}
</script>
</body>
</html>